function player(config){
    if(config.url.indexOf(".m3u8")>0||config.url.indexOf(".mp4")>0||config.url.indexOf(".flv")>0){
        TheDPlayer(config.url,config.vkey,config.next,config.contextmenu,config.contextlink);
    }else{
        $.ajaxSettings.timeout='30000'; 
        $.ajaxSettings.async = true;
    	$.post("API.php", {"url":config.url,"time":config.time,"key":config.key},
    	function(data) {
    		if(data.code=="200"){
    			TheDPlayer(data.url,config.vkey,config.next,config.contextmenu,config.contextlink);
    		}else{
    			TheError();
    		}
    	},'json').error(function (xhr, status, info) {
            TheError();
        });
    }
}
function TheDPlayer(url,vkey,nexturl,contextmenu,contextlink){
    $("#loading").remove();
    $("body").append("<div id=\"dplayer\"></div>");
    if(url.indexOf("m3u8")>0){
        type="hls";
    }else if(url.indexOf("mp4")>0){
        type="mp4";
    }else if(url.indexOf("flv")>0){
        type="flv";
    }
    var dp = new DPlayer({
        container: document.getElementById("dplayer"),
        autoplay: true,
        screenshot: false,
        hotkey: true,
        preload:"auto",
        volume: 1,
        video: {
            url: url,
            live: false,
            type: type
        },
        contextmenu: [
            {
                text: contextmenu,link: contextlink
            }
        ]
    });
    dp.on('loadstart',function(){
        var video = dp.video;
        var currentTime = localStorage.getItem(vkey);
        video.addEventListener("loadedmetadata",function(){
            this.currentTime = currentTime;
        });
        video.addEventListener("timeupdate",function(){
            var currentTime = Math.floor(video.currentTime);
            localStorage.setItem(vkey,currentTime);
        });
        video.addEventListener("ended",function(){
            localStorage.removeItem(vkey);
            if(!!nexturl){
                top.location.href=nexturl;
            }
        });
    });
}
function TheError(){
    $("body").append("<div id=\"error\"><h1>解析失败，请切换线路或刷新！</h1></div>");
	$("#loading").remove();
}